//
//  DeviceListModel.m
//
//  Created by  殷聃 on 2019/7/9
//  Copyright (c) 2019 yek. All rights reserved.
//

#import "DeviceListModel.h"


NSString *const kDeviceListModelId = @"id";
NSString *const kDeviceListModelIsBinding = @"isBinding";
NSString *const kDeviceListModelDeviceMac = @"deviceMac";
NSString *const kDeviceListModelDeviceSn = @"deviceSn";
NSString *const kDeviceListModelDeviceQr = @"deviceQr";
NSString *const kDeviceListModelDeviceType = @"deviceType";
NSString *const kDeviceListModelDelete = @"delete";
NSString *const kDeviceListModelIsDelete = @"isDelete";
NSString *const kDeviceListModelAddUser = @"addUser";
NSString *const kDeviceListModelBinding = @"binding";
NSString *const kDeviceListModelAddTime = @"addTime";
NSString *const kDeviceListModelDeviceStatus = @"deviceStatus";
NSString *const kDeviceListModelUpdateUser = @"updateUser";
NSString *const kDeviceListModelDeviceCode = @"deviceCode";
NSString *const kDeviceListModelUpdateTime = @"updateTime";
NSString *const kDeviceListModelOnline = @"online";



@interface DeviceListModel ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation DeviceListModel

@synthesize internalBaseClassIdentifier = _internalBaseClassIdentifier;
@synthesize isBinding = _isBinding;
@synthesize deviceMac = _deviceMac;
@synthesize deviceSn = _deviceSn;
@synthesize deviceQr = _deviceQr;
@synthesize deviceType = _deviceType;
@synthesize delete = _delete;
@synthesize isDelete = _isDelete;
@synthesize addUser = _addUser;
@synthesize binding = _binding;
@synthesize addTime = _addTime;
@synthesize deviceStatus = _deviceStatus;
@synthesize updateUser = _updateUser;
@synthesize deviceCode = _deviceCode;
@synthesize updateTime = _updateTime;
@synthesize online = _online;


+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict
{
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if(self && [dict isKindOfClass:[NSDictionary class]]) {
            self.internalBaseClassIdentifier = [[self objectOrNilForKey:kDeviceListModelId fromDictionary:dict] doubleValue];
            self.isBinding = [[self objectOrNilForKey:kDeviceListModelIsBinding fromDictionary:dict] boolValue];
            self.deviceMac = [self objectOrNilForKey:kDeviceListModelDeviceMac fromDictionary:dict];
            self.deviceSn = [self objectOrNilForKey:kDeviceListModelDeviceSn fromDictionary:dict];
            self.deviceQr = [self objectOrNilForKey:kDeviceListModelDeviceQr fromDictionary:dict];
            self.deviceType = [self objectOrNilForKey:kDeviceListModelDeviceType fromDictionary:dict];
            self.delete = [[self objectOrNilForKey:kDeviceListModelDelete fromDictionary:dict] boolValue];
            self.isDelete = [[self objectOrNilForKey:kDeviceListModelIsDelete fromDictionary:dict] boolValue];
            self.addUser = [self objectOrNilForKey:kDeviceListModelAddUser fromDictionary:dict];
            self.binding = [[self objectOrNilForKey:kDeviceListModelBinding fromDictionary:dict] boolValue];
            self.addTime = [[self objectOrNilForKey:kDeviceListModelAddTime fromDictionary:dict] doubleValue];
            self.deviceStatus = [self objectOrNilForKey:kDeviceListModelDeviceStatus fromDictionary:dict];
            self.updateUser = [self objectOrNilForKey:kDeviceListModelUpdateUser fromDictionary:dict];
            self.deviceCode = [self objectOrNilForKey:kDeviceListModelDeviceCode fromDictionary:dict];
            self.updateTime = [[self objectOrNilForKey:kDeviceListModelUpdateTime fromDictionary:dict] doubleValue];
        self.online = [[self objectOrNilForKey:kDeviceListModelOnline fromDictionary:dict] integerValue];

    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:[NSNumber numberWithDouble:self.internalBaseClassIdentifier] forKey:kDeviceListModelId];
    [mutableDict setValue:[NSNumber numberWithBool:self.isBinding] forKey:kDeviceListModelIsBinding];
    [mutableDict setValue:self.deviceMac forKey:kDeviceListModelDeviceMac];
    [mutableDict setValue:self.deviceSn forKey:kDeviceListModelDeviceSn];
    [mutableDict setValue:self.deviceQr forKey:kDeviceListModelDeviceQr];
    [mutableDict setValue:self.deviceType forKey:kDeviceListModelDeviceType];
    [mutableDict setValue:[NSNumber numberWithBool:self.delete] forKey:kDeviceListModelDelete];
    [mutableDict setValue:[NSNumber numberWithBool:self.isDelete] forKey:kDeviceListModelIsDelete];
    [mutableDict setValue:self.addUser forKey:kDeviceListModelAddUser];
    [mutableDict setValue:[NSNumber numberWithBool:self.binding] forKey:kDeviceListModelBinding];
    [mutableDict setValue:[NSNumber numberWithDouble:self.addTime] forKey:kDeviceListModelAddTime];
    [mutableDict setValue:self.deviceStatus forKey:kDeviceListModelDeviceStatus];
    [mutableDict setValue:self.updateUser forKey:kDeviceListModelUpdateUser];
    [mutableDict setValue:self.deviceCode forKey:kDeviceListModelDeviceCode];
    [mutableDict setValue:[NSNumber numberWithDouble:self.updateTime] forKey:kDeviceListModelUpdateTime];
    [mutableDict setValue:[NSNumber numberWithInt:self.online] forKey:kDeviceListModelOnline];

    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description 
{
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}


#pragma mark - NSCoding Methods

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super init];

    self.internalBaseClassIdentifier = [aDecoder decodeDoubleForKey:kDeviceListModelId];
    self.isBinding = [aDecoder decodeBoolForKey:kDeviceListModelIsBinding];
    self.deviceMac = [aDecoder decodeObjectForKey:kDeviceListModelDeviceMac];
    self.deviceSn = [aDecoder decodeObjectForKey:kDeviceListModelDeviceSn];
    self.deviceQr = [aDecoder decodeObjectForKey:kDeviceListModelDeviceQr];
    self.deviceType = [aDecoder decodeObjectForKey:kDeviceListModelDeviceType];
    self.delete = [aDecoder decodeBoolForKey:kDeviceListModelDelete];
    self.isDelete = [aDecoder decodeBoolForKey:kDeviceListModelIsDelete];
    self.addUser = [aDecoder decodeObjectForKey:kDeviceListModelAddUser];
    self.binding = [aDecoder decodeBoolForKey:kDeviceListModelBinding];
    self.addTime = [aDecoder decodeDoubleForKey:kDeviceListModelAddTime];
    self.deviceStatus = [aDecoder decodeObjectForKey:kDeviceListModelDeviceStatus];
    self.updateUser = [aDecoder decodeObjectForKey:kDeviceListModelUpdateUser];
    self.deviceCode = [aDecoder decodeObjectForKey:kDeviceListModelDeviceCode];
    self.updateTime = [aDecoder decodeDoubleForKey:kDeviceListModelUpdateTime];
    self.online = [aDecoder decodeIntForKey:kDeviceListModelOnline];
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{

    [aCoder encodeDouble:_internalBaseClassIdentifier forKey:kDeviceListModelId];
    [aCoder encodeBool:_isBinding forKey:kDeviceListModelIsBinding];
    [aCoder encodeObject:_deviceMac forKey:kDeviceListModelDeviceMac];
    [aCoder encodeObject:_deviceSn forKey:kDeviceListModelDeviceSn];
    [aCoder encodeObject:_deviceQr forKey:kDeviceListModelDeviceQr];
    [aCoder encodeObject:_deviceType forKey:kDeviceListModelDeviceType];
    [aCoder encodeBool:_delete forKey:kDeviceListModelDelete];
    [aCoder encodeBool:_isDelete forKey:kDeviceListModelIsDelete];
    [aCoder encodeObject:_addUser forKey:kDeviceListModelAddUser];
    [aCoder encodeBool:_binding forKey:kDeviceListModelBinding];
    [aCoder encodeDouble:_addTime forKey:kDeviceListModelAddTime];
    [aCoder encodeObject:_deviceStatus forKey:kDeviceListModelDeviceStatus];
    [aCoder encodeObject:_updateUser forKey:kDeviceListModelUpdateUser];
    [aCoder encodeObject:_deviceCode forKey:kDeviceListModelDeviceCode];
    [aCoder encodeDouble:_updateTime forKey:kDeviceListModelUpdateTime];
    [aCoder encodeInt:_online forKey:kDeviceListModelOnline];
}

- (id)copyWithZone:(NSZone *)zone
{
    DeviceListModel *copy = [[DeviceListModel alloc] init];
    
    if (copy) {

        copy.internalBaseClassIdentifier = self.internalBaseClassIdentifier;
        copy.isBinding = self.isBinding;
        copy.deviceMac = [self.deviceMac copyWithZone:zone];
        copy.deviceSn = [self.deviceSn copyWithZone:zone];
        copy.deviceQr = [self.deviceQr copyWithZone:zone];
        copy.deviceType = [self.deviceType copyWithZone:zone];
        copy.delete = self.delete;
        copy.isDelete = self.isDelete;
        copy.addUser = [self.addUser copyWithZone:zone];
        copy.binding = self.binding;
        copy.addTime = self.addTime;
        copy.deviceStatus = [self.deviceStatus copyWithZone:zone];
        copy.updateUser = [self.updateUser copyWithZone:zone];
        copy.deviceCode = [self.deviceCode copyWithZone:zone];
        copy.updateTime = self.updateTime;
        copy.online = self.online;
    }
    
    return copy;
}


@end
